home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************
-
- Fast DES program module
- - Copyright 1991, Christian Beaumont
-
- This program is free software; you can
- redistribute it and/or modify it as you see fit.
-
- This program is distributed in the hope that it
- will be useful, but WITHOUT ANY WARRANTY; without
- even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE.
-
- *****************************************************\
-
- #include <stdio.h>
- #include <string.h>
- #include "fdes.h"
-
- struct passwd *getpwent(char *fn)
- {
- static FILE *f = NULL;
- static struct passwd p;
- char s[200];
- int l;
-
- if(f == NULL)
- if((f = fopen(fn,"r")) == NULL){
- perror("File error");
- return NULL;
- }
-
- for(;;){
- if(fgets(s,200,f)==NULL){
- fclose(f);
- f = NULL;
- return NULL;
- }
-
- l = strlen(s)-1;
-
- s[l] = '\0';
-
- if(l == 0)
- continue;
-
- p.pw_user[0] = '\0';
- p.pw_passwd[0] = '\0';
- p.pw_gecos[0] = '\0';
- p.pw_dir[0] = '\0';
- p.pw_shell[0] = '\0';
-
- strncat(p.pw_user,strtok(s,":"),9);
- strncat(p.pw_passwd,strtok(NULL,":"),13);
- sscanf(strtok(NULL,":"),"%d",&p.pw_uid);
- sscanf(strtok(NULL,":"),"%d",&p.pw_gid);
- strncat(p.pw_gecos,strtok(NULL,":"),39);
- strncat(p.pw_dir,strtok(NULL,":"),39);
- strncat(p.pw_shell,strtok(NULL,":"),20);
- return &p;
- }
- }
-
-
-